import requests,unittest

class keji(unittest.TestCase):
    host = "https://10.59.9.18/"

    userId=None
    sessionId=None
    #登录 login
    def test_01_login(self):
        url=keji.host+"/techApi/user/v1/login"
        json={'phone':'18825853329','pwd':'S0hBZElnMkExQml6T21vYVRacVNmN2lSRHUxNGVsK2JMSXlBUkpWSmJsM0JJYkN0M0RYaTZLMDh0N3pLSU1FYzgvR1FFZzhZMExYaXFqNWE1WlBiUGd4bWdYWFVvZ09VTzdYcmpZOUZRRStqUkhqN1RVc25GSDJvaWp1STI3Tm1WdWpDdlRZTUpGVit5WGRMOTZlZlY3eTlKWVJENzlIdzlPN2xNMWQ5eUEwPQ=='}
        login=requests.post(url=url,data=json,verify=False)
        print(login.json())
        keji.userId=login.json()['result']['userId']
        print(keji.userId)
        keji.sessionId=login.json()['result']['sessionId']
        print(keji.sessionId)
        self.assertEqual(keji.userId,369)
        self.assertTrue(keji.sessionId,'1743595885414369')

    #查询一下我的群 findqun
    def test_02_findqun(self):
        url = keji.host + "/techApi/group/verify/v1/findGroupsByUserId"
        headers = {'userId': str(keji.userId), 'sessionId': keji.sessionId}
        findqun=requests.get(url=url,headers=headers,verify=False)
        print(findqun.json())
        self.assertEqual(findqun.json()['message'],'查询成功')
        self.assertNotEqual(findqun.json()['status'],'1001')

    #创建群 create
    def test_03_create(self):
        url = keji.host + "/techApi/group/verify/v1/createGroup"
        headers={'userId':str(keji.userId),'sessionId':keji.sessionId}
        json={'name':'宫本武藏天下无敌','description':'进群就是一家人'}
        create=requests.post(url=url,headers=headers,data=json,verify=False)
        print(create.json())
        self.assertEqual(create.json()['status'], '1001')
        self.assertNotEqual(create.json()['message'], '创建成功')

    #修改群名 gropname
    def test_04_gropname(self):
        url = keji.host + "/techApi/group/verify/v1/modifyGroupName"
        headers = {'userId': str(keji.userId), 'sessionId': keji.sessionId}
        json = {'groupId': 12, 'groupName': '一叶知秋'}
        gropname=requests.put(url=url,headers=headers,data=json,verify=False)
        print(gropname.json())
        self.assertEqual(gropname.json()['status'], '1001')
        self.assertNotEqual(gropname.json()['message'], '修改群名称成功')

    #解散群组 disgrop
    def test_05_disgrop(self):
        url = keji.host + "/techApi/group/verify/v1/disbandGroup"
        headers = {'userId': str(keji.userId), 'sessionId': keji.sessionId}
        # 将 groupId 放在 URL 参数中
        params = {'groupId': 12}  # 不需要 int()，直接传数字
        disgrop = requests.delete(url=url, verify=False, headers=headers, params=params)
        print(disgrop.json())
        self.assertIn(disgrop.json()['status'],'1001')
        self.assertNotIn(disgrop.json()['message'],'成功')


#执行
if __name__ == '__main__':
    unittest.main()